package com.xyx.bloodoxygenlib.impls;

import java.util.Vector;

public abstract class BaseProtocol {
    private static byte[] crc_table;

    public abstract int checkIntactCnt(Vector<Byte> vector);

    static {
        byte[] bArr = new byte[256];
        bArr[1] = 94;
        bArr[2] = -68;
        bArr[3] = -30;
        bArr[4] = 97;
        bArr[5] = 63;
        bArr[6] = -35;
        bArr[7] = -125;
        bArr[8] = -62;
        bArr[9] = -100;
        bArr[10] = 126;
        bArr[11] = 32;
        bArr[12] = -93;
        bArr[13] = -3;
        bArr[14] = 31;
        bArr[15] = 65;
        bArr[16] = -99;
        bArr[17] = -61;
        bArr[18] = 33;
        bArr[19] = Byte.MAX_VALUE;
        bArr[20] = -4;
        bArr[21] = -94;
        bArr[22] = 64;
        bArr[23] = 30;
        bArr[24] = 95;
        bArr[25] = 1;
        bArr[26] = -29;
        bArr[27] = -67;
        bArr[28] = 62;
        bArr[29] = 96;
        bArr[30] = -126;
        bArr[31] = -36;
        bArr[32] = 35;
        bArr[33] = 125;
        bArr[34] = -97;
        bArr[35] = -63;
        bArr[36] = 66;
        bArr[37] = 28;
        bArr[38] = -2;
        bArr[39] = -96;
        bArr[40] = -31;
        bArr[41] = -65;
        bArr[42] = 93;
        bArr[43] = 3;
        bArr[44] = Byte.MIN_VALUE;
        bArr[45] = -34;
        bArr[46] = 60;
        bArr[47] = 98;
        bArr[48] = -66;
        bArr[49] = -32;
        bArr[50] = 2;
        bArr[51] = 92;
        bArr[52] = -33;
        bArr[53] = -127;
        bArr[54] = 99;
        bArr[55] = 61;
        bArr[56] = 124;
        bArr[57] = 34;
        bArr[58] = -64;
        bArr[59] = -98;
        bArr[60] = 29;
        bArr[61] = 67;
        bArr[62] = -95;
        bArr[63] = -1;
        bArr[64] = 70;
        bArr[65] = 24;
        bArr[66] = -6;
        bArr[67] = -92;
        bArr[68] = 39;
        bArr[69] = 121;
        bArr[70] = -101;
        bArr[71] = -59;
        bArr[72] = -124;
        bArr[73] = -38;
        bArr[74] = 56;
        bArr[75] = 102;
        bArr[76] = -27;
        bArr[77] = -69;
        bArr[78] = 89;
        bArr[79] = 7;
        bArr[80] = -37;
        bArr[81] = -123;
        bArr[82] = 103;
        bArr[83] = 57;
        bArr[84] = -70;
        bArr[85] = -28;
        bArr[86] = 6;
        bArr[87] = 88;
        bArr[88] = 25;
        bArr[89] = 71;
        bArr[90] = -91;
        bArr[91] = -5;
        bArr[92] = 120;
        bArr[93] = 38;
        bArr[94] = -60;
        bArr[95] = -102;
        bArr[96] = 101;
        bArr[97] = 59;
        bArr[98] = -39;
        bArr[99] = -121;
        bArr[100] = 4;
        bArr[101] = 90;
        bArr[102] = -72;
        bArr[103] = -26;
        bArr[104] = -89;
        bArr[105] = -7;
        bArr[106] = 27;
        bArr[107] = 69;
        bArr[108] = -58;
        bArr[109] = -104;
        bArr[110] = 122;
        bArr[111] = 36;
        bArr[112] = -8;
        bArr[113] = -90;
        bArr[114] = 68;
        bArr[115] = 26;
        bArr[116] = -103;
        bArr[117] = -57;
        bArr[118] = 37;
        bArr[119] = 123;
        bArr[120] = 58;
        bArr[121] = 100;
        bArr[122] = -122;
        bArr[123] = -40;
        bArr[124] = 91;
        bArr[125] = 5;
        bArr[126] = -25;
        bArr[127] = -71;
        bArr[128] = -116;
        bArr[129] = -46;
        bArr[130] = 48;
        bArr[131] = 110;
        bArr[132] = -19;
        bArr[133] = -77;
        bArr[134] = 81;
        bArr[135] = 15;
        bArr[136] = 78;
        bArr[137] = 16;
        bArr[138] = -14;
        bArr[139] = -84;
        bArr[140] = 47;
        bArr[141] = 113;
        bArr[142] = -109;
        bArr[143] = -51;
        bArr[144] = 17;
        bArr[145] = 79;
        bArr[146] = -83;
        bArr[147] = -13;
        bArr[148] = 112;
        bArr[149] = 46;
        bArr[150] = -52;
        bArr[151] = -110;
        bArr[152] = -45;
        bArr[153] = -115;
        bArr[154] = 111;
        bArr[155] = 49;
        bArr[156] = -78;
        bArr[157] = -20;
        bArr[158] = 14;
        bArr[159] = 80;
        bArr[160] = -81;
        bArr[161] = -15;
        bArr[162] = 19;
        bArr[163] = 77;
        bArr[164] = -50;
        bArr[165] = -112;
        bArr[166] = 114;
        bArr[167] = 44;
        bArr[168] = 109;
        bArr[169] = 51;
        bArr[170] = -47;
        bArr[171] = -113;
        bArr[172] = 12;
        bArr[173] = 82;
        bArr[174] = -80;
        bArr[175] = -18;
        bArr[176] = 50;
        bArr[177] = 108;
        bArr[178] = -114;
        bArr[179] = -48;
        bArr[180] = 83;
        bArr[181] = 13;
        bArr[182] = -17;
        bArr[183] = -79;
        bArr[184] = -16;
        bArr[185] = -82;
        bArr[186] = 76;
        bArr[187] = 18;
        bArr[188] = -111;
        bArr[189] = -49;
        bArr[190] = 45;
        bArr[191] = 115;
        bArr[192] = -54;
        bArr[193] = -108;
        bArr[194] = 118;
        bArr[195] = 40;
        bArr[196] = -85;
        bArr[197] = -11;
        bArr[198] = 23;
        bArr[199] = 73;
        bArr[200] = 8;
        bArr[201] = 86;
        bArr[202] = -76;
        bArr[203] = -22;
        bArr[204] = 105;
        bArr[205] = 55;
        bArr[206] = -43;
        bArr[207] = -117;
        bArr[208] = 87;
        bArr[209] = 9;
        bArr[210] = -21;
        bArr[211] = -75;
        bArr[212] = 54;
        bArr[213] = 104;
        bArr[214] = -118;
        bArr[215] = -44;
        bArr[216] = -107;
        bArr[217] = -53;
        bArr[218] = 41;
        bArr[219] = 119;
        bArr[220] = -12;
        bArr[221] = -86;
        bArr[222] = 72;
        bArr[223] = 22;
        bArr[224] = -23;
        bArr[225] = -73;
        bArr[226] = 85;
        bArr[227] = 11;
        bArr[228] = -120;
        bArr[229] = -42;
        bArr[230] = 52;
        bArr[231] = 106;
        bArr[232] = 43;
        bArr[233] = 117;
        bArr[234] = -105;
        bArr[235] = -55;
        bArr[236] = 74;
        bArr[237] = 20;
        bArr[238] = -10;
        bArr[239] = -88;
        bArr[240] = 116;
        bArr[241] = 42;
        bArr[242] = -56;
        bArr[243] = -106;
        bArr[244] = 21;
        bArr[245] = 75;
        bArr[246] = -87;
        bArr[247] = -9;
        bArr[248] = -74;
        bArr[249] = -24;
        bArr[250] = 10;
        bArr[251] = 84;
        bArr[252] = -41;
        bArr[253] = -119;
        bArr[254] = 107;
        bArr[255] = 53;
        crc_table = bArr;
    }

    public static boolean checkCRC(Vector<Byte> buffer, int begin, int end) {
        byte cur_crc = 0;
        for (int i = begin; i < end; i++) {
            cur_crc = crc_table[(buffer.get(i).byteValue() ^ cur_crc) & 255];
        }
        return cur_crc == buffer.get(end).byteValue();
    }

    public static void getCRC(byte[] srcCRC, int temp) {
        byte Old_CRC = 0;
        int i = 0;
        while (i < temp - 1) {
            Old_CRC = crc_table[(srcCRC[i] ^ Old_CRC) & 255];
            i++;
        }
        srcCRC[i] = Old_CRC;
    }
}
